package com.fang.networkdisk.util;

import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Bernie_fang
 * @Description: 封装工具类
 * @create 2025/1/27 18:01
 **/
public class NDBeanUtils {

    public static Object copyListProperties(Object source, Object target) {
        BeanUtils.copyProperties(source, target);
        return target;
    }

    public static <S, T> List<T> copyListProperties(List<S> sourceList, Class<T> targetClass) {
        List<T> targetList = new ArrayList<>();
        try {
            for (S source : sourceList) {
                T target = targetClass.newInstance();
                BeanUtils.copyProperties(source, target);
                targetList.add(target);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return targetList;
    }


    /**
     * Description: 对类判空
     * @Author: Bernie_fang
     * @Since: 2025/1/30 15:20
     * @param object:
     * @return: boolean
     **/
    public static boolean isObjectEmpty(Object object) {
        return ObjectUtils.isEmpty(object);
    }

    public static boolean isObjectNotEmpty(Object object) {
        return !isObjectEmpty(object);
    }
}
